<template>
  <el-dropdown trigger="click" @command="handleSetSize" style="display: flex;align-items: center;">
    <div>
      <svg-icon icon-class="size" />
    </div>

    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item v-for="item of sizeOptions" :key="item.value" :disabled="size===item.value" :command="item.value">
          {{ item.label }}
        </el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>

<script>

export default {
  data() {
    return {
      sizeOptions: [
        // { label: 'Default', value: 'default' },
        // { label: 'Medium', value: 'medium' },
        // { label: 'Small', value: 'small' },
        // { label: 'Mini', value: 'mini' }
        { label: 'Default', value: 'default' },
        { label: 'Small', value: 'small' },
        { label: 'Large', value: 'large' }
      ]
    }
  },
  computed: {
    size() {
      return this.$store.getters.size
    }
  }
}
</script>

<script setup>
import { ElMessage } from 'element-plus'
import { inject } from 'vue'
import { useStore } from 'vuex'
import { useRoute } from 'vue-router'

const store = useStore()
const route = useRoute()
const reload = inject('reload')

const refreshView = () => {
  store.dispatch('tagsView/delAllCachedViews', route)
  reload()
}

const handleSetSize = size => {
  store.dispatch('app/setSize', size)
  refreshView()
  ElMessage({
    message: 'Switch Size Success',
    type: 'success'
  })
}
</script>

<style lang="scss" scoped>
.svg-c {
  height: 100%;
  display: flex;
  align-items: center;
}
</style>
